﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;

namespace YArchitech.Plumbing.ParamForm
{
	public partial class AdvancedSettingForm : System.Windows.Forms.Form
	{
		public AdvancedSettingForm(OptionData option)
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
			this.option = option;
		}

		private void AdvancedSettingForm_Load(object sender, EventArgs e)
		{
			this.cbxIndoorPipeUnit.Items.AddRange(new object[]
			{
				"d",
				"φ",
				"DN"
			});
			this.cbxPressureValve.Items.AddRange(new object[]
			{
				"入户处",
				"公用立管",
				"无"
			});
			this.LoadData();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.hyTxtLocalCoefficient.Text == "" || this.hyTxtLocalResistance.Text == "" || this.hyTxtPressureValve.Text == "" || this.hyTxtTemValve.Text == "")
			{
				YJKMessageBox.Information("参数不能为空。");
				return;
			}
			this.SaveData();
			base.DialogResult = DialogResult.OK;
		}

		private void LoadData()
		{
			this.cbxPressureValve.SelectedIndex = this.option.DPValvePosition - 1;
			this.hyTxtLocalCoefficient.Text = this.option.ResistanceLocal.ToString();
			this.hyTxtLocalResistance.Text = this.option.Resistance.ToString();
			this.hyTxtPressureValve.Text = this.option.DiffDPValve.ToString();
			this.hyTxtTemValve.Text = this.option.DiffTCValve.ToString();
			this.cbxIndoorPipeUnit.SelectedIndex = this.option.MaterialInternal - 1;
		}

		private void SaveData()
		{
			this.option.DPValvePosition = this.cbxPressureValve.SelectedIndex + 1;
			this.option.ResistanceLocal = double.Parse(this.hyTxtLocalCoefficient.Text);
			this.option.Resistance = double.Parse(this.hyTxtLocalResistance.Text);
			this.option.DiffDPValve = double.Parse(this.hyTxtPressureValve.Text);
			this.option.DiffTCValve = double.Parse(this.hyTxtTemValve.Text);
			this.option.MaterialInternal = this.cbxIndoorPipeUnit.SelectedIndex + 1;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void cbxIndoorPipeUnit_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.option.MaterialInternal = this.cbxIndoorPipeUnit.SelectedIndex + 1;
		}

		private OptionData option;
	}
}
